package com.itheima.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.bean.DishFlavor;
import com.itheima.dao.DishFlavorDao;
import com.itheima.service.DishFlavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


@Service
@Transactional
public class DishFlavorServiceImpl implements DishFlavorService {

    @Resource
    private DishFlavorDao dishFlavorDao;

    @Override
    public int add(DishFlavor dishFlavor) {


        System.err.println(dishFlavor);
        return dishFlavorDao.insert(dishFlavor);

    }

    @Override
    public int deleteByDishId(long dishid) {


        //构建条件对象
        LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();


        lqw.eq(DishFlavor::getDishId, dishid);

        return dishFlavorDao.delete(lqw);

    }

    @Override
    public List<DishFlavor> findByDishId(long dishid) {

        //定义条件
        LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();
        lqw.eq(DishFlavor::getDishId, dishid);

        return dishFlavorDao.selectList(lqw);
    }
}
